#!/bin/sh

VERSION=$1

ROOT=~/sourceforge

SRCDIR=$ROOT/roadmap
ARMDIR=$ROOT/arm/familiar/roadmap/src
IPKGDIR=$ROOT/arm/familiar/roadmap/ipkg

rm -rf $IPKGDIR

# --------------------------------------------------------------------------
echo "Building package 'roadmap' .."

mkdir -p $IPKGDIR/roadmap/CONTROL
sed -e s/_VERSION_/$VERSION/ $SRCDIR/src/ipkg/roadmap.control >$IPKGDIR/roadmap/CONTROL/control
cp $SRCDIR/src/ipkg/roadmap.postinst $IPKGDIR/roadmap/CONTROL/postinst
cp $SRCDIR/src/ipkg/roadmap.postrm   $IPKGDIR/roadmap/CONTROL/postrm
chmod a+x $IPKGDIR/roadmap/CONTROL/postinst $IPKGDIR/roadmap/CONTROL/postrm

mkdir -p $IPKGDIR/roadmap/usr/bin
cp $ARMDIR/gtk2/gtkroadmap $IPKGDIR/roadmap/usr/bin/roadmap
cp $ARMDIR/gtk2/gtkroadgps $IPKGDIR/roadmap/usr/bin/roadgps
cp $ARMDIR/rdmghost   $IPKGDIR/roadmap/usr/bin/rdmghost
cp $ARMDIR/rdmfriends $IPKGDIR/roadmap/usr/bin/rdmfriends
cp $ARMDIR/rdmkismet  $IPKGDIR/roadmap/usr/bin/rdmkismet

mkdir -p $IPKGDIR/roadmap/usr/share/applications
cp $SRCDIR/src/roadmap.desktop $IPKGDIR/roadmap/usr/share/applications

mkdir -p $IPKGDIR/roadmap/usr/share/pixmaps
cp $SRCDIR/src/roadmap*.png $IPKGDIR/roadmap/usr/share/pixmaps
cp $SRCDIR/src/icons/rm_*.png $IPKGDIR/roadmap/usr/share/pixmaps

mkdir -p $IPKGDIR/roadmap/usr/share/roadmap
cp $SRCDIR/src/schema      $IPKGDIR/roadmap/usr/share/roadmap/schema
cp $SRCDIR/src/sprites     $IPKGDIR/roadmap/usr/share/roadmap/sprites
cp $SRCDIR/src/drivers     $IPKGDIR/roadmap/usr/share/roadmap/drivers
cp $SRCDIR/web/manual.html $IPKGDIR/roadmap/usr/share/roadmap/manual.html
cp $SRCDIR/web/apt_toc.gif $IPKGDIR/roadmap/usr/share/roadmap/apt_toc.gif

sed -e 's/Map.Path:.*$/Map.Path: \&\/maps,\/usr\/share\/roadmap,\/mnt\/hda\/share\/roadmap\/,\/mnt\/card\/share\/roadmap/' < $SRCDIR/src/preferences > $IPKGDIR/roadmap/usr/share/roadmap/preferences

$ROOT/roadmap/ipkg-build -o root -g root $IPKGDIR/roadmap $IPKGDIR


# --------------------------------------------------------------------------
if [ -e $ARMDIR/buildmap ] ; then

  echo "Building package 'buildmap' .."

  mkdir -p $IPKGDIR/buildmap/CONTROL
  sed -e s/_VERSION_/$VERSION/ $SRCDIR/src/ipkg/roadmap-build.control >$IPKGDIR/buildmap/CONTROL/control

  mkdir -p $IPKGDIR/buildmap/usr/bin
  cp $ARMDIR/buildmap $IPKGDIR/buildmap/usr/bin/buildmap
  cp $ARMDIR/buildus  $IPKGDIR/buildmap/usr/bin/buildus
  cp $ARMDIR/dumpmap  $IPKGDIR/buildmap/usr/bin/dumpmap

  roadmap/ipkg-build -o root -g root `pwd`/$IPKGDIR/buildmap `pwd`/$IPKGDIR

fi

